//
//  DiscountsCheckUserInfoVC.swift
//  d11
//
//  Created by inara on 2018/10/31.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
import SwiftyJSON

//(四)继承代理：
class DiscountsCheckUserInfoVC: BXBaseVC,UITextFieldDelegate,ZHFAddTitleAddressViewDelegate {
    lazy var addTitleAddressView : ZHFAddTitleAddressView = ZHFAddTitleAddressView()
    @IBOutlet weak var realNameView: UIView!
    
    @IBOutlet weak var emailView: UIView!
    @IBOutlet weak var emailVerificationCodeView: UIView!
    
    @IBOutlet weak var phoneView: UIView!
    @IBOutlet weak var phoneVerificationCodeView: UIView!
    
    @IBOutlet weak var adressView: UIView!
    @IBOutlet weak var realNameTf: UITextField!
    
    @IBOutlet weak var emailTf: UITextField!
    @IBOutlet weak var emailCodeTf: UITextField!
    
    @IBOutlet weak var phoneTf: UITextField!
    @IBOutlet weak var phoneCodeTf: UITextField!
    
    @IBOutlet weak var adressBtn: UIButton!
    @IBOutlet weak var checkBtn: UIButton!
    
    @IBOutlet weak var getEmailVerificationBtn: UIButton!
    @IBOutlet weak var getVerificationCode: UIButton!
    
    
    @IBOutlet weak var nameHeight: NSLayoutConstraint!
    @IBOutlet weak var phoneHeight: NSLayoutConstraint!
    //    @IBOutlet weak var nameHeight: NSLayoutConstraint!
    //姓名下方缝隙
    @IBOutlet weak var nameTap: NSLayoutConstraint!
    //手机验证下方tap
    @IBOutlet weak var phoneTap: NSLayoutConstraint!
    
    @IBOutlet weak var phoneCodeHeight: NSLayoutConstraint!
    
    @IBOutlet weak var phoneCodeTap: NSLayoutConstraint!
    
    @IBOutlet weak var emailHeight: NSLayoutConstraint!
    //
    @IBOutlet weak var emailTap: NSLayoutConstraint!
    
    @IBOutlet weak var emailCodeHeight: NSLayoutConstraint!
    
    @IBOutlet weak var codeTap: NSLayoutConstraint!
    
    @IBOutlet weak var addressDetailView: UIView!
    @IBOutlet weak var addressDetail: UITextField!
    @IBOutlet weak var adressHeight: NSLayoutConstraint!
    //    @IBOutlet weak var emailHeight: NSLayoutConstraint!
    //    @IBOutlet weak var emailCodeHeight: NSLayoutConstraint!
    //    @IBOutlet weak var emailTap: NSLayoutConstraint!
    //
    //    @IBOutlet weak var phoneHeight: NSLayoutConstraint!
    //    @IBOutlet weak var phoneTap: NSLayoutConstraint!
    //    @IBOutlet weak var phoneCodeHeight: NSLayoutConstraint!
    //
    //    @IBOutlet weak var adressHeight: NSLayoutConstraint!
    //
    var realNameIsHidden = NSString()
    var emailIsHidden = NSString()
    var emailCodeIsHidden = NSString()
    var phoneCheckIsHidden = NSString()
    var phoneCodeIsHidden = NSString()
    var adressIsHidden = NSString()
    
    @IBOutlet weak var textFild: UITextField!
    @IBOutlet weak var LabProvice: UILabel!
    var timer = TimerHander()
    var timer2 = TimerHander()
    var stringIDs : String?
    var isWithdraw : Bool = false
    var isBindingBank : Bool = false
    //(五)实现协议方法：必须全部实现
    //更改地址
    func change( adress: String) {
        if (adress != nil) {
            adressBtn.setTitle(adress, for:.normal)
        }
    }
    func cancelBtnClick(titleAddress: String, titleID: String) {
        LabProvice.text = titleAddress.count > 0 ? titleAddress : ""
        textFild.text = titleAddress.count > 0 ? titleAddress : ""
        stringIDs = titleID
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
      
       self.title = "完善信息"
        
        self.realNameView.layer.borderWidth = 0
        self.emailView.layer.borderWidth = 0
        self.emailVerificationCodeView.layer.borderWidth = 0
        self.phoneView.layer.borderWidth = 0
        self.phoneVerificationCodeView.layer.borderWidth = 0
        self.adressView.layer.borderWidth = 0
        
        self.getEmailVerificationBtn.clipsToBounds = true
        self.getEmailVerificationBtn.layer.cornerRadius = 6
        self.getEmailVerificationBtn.layer.borderColor = RGBAlpa(255,198,116,1).cgColor
        self.getEmailVerificationBtn.layer.borderWidth = 0.5
        self.getVerificationCode.clipsToBounds = true
        self.getVerificationCode.layer.cornerRadius = 6
        self.getVerificationCode.layer.borderColor = RGBAlpa(255,198,116,1).cgColor
        self.getVerificationCode.layer.borderWidth = 0.5
        
        self.checkIsShow()
        // Do any additional setup after loading the view.
        phoneTf.delegate = self
        phoneTf.tag = 1001
        setUI()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        addTitleAddressView.removeFromSuperview()
    }
    
    
    func setUI()  {
        //这是用户的ID
        addTitleAddressView.title = "选择地址"
        addTitleAddressView.userID = 7
        addTitleAddressView.delegate = self
        addTitleAddressView.defaultHeight = 350
        UIApplication.shared.delegate?.window??.addSubview(addTitleAddressView.initAddressView())
    }
    
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if textField.tag == 1001{
            let text = textField.text!
      
            let len = text.count + string.count - range.length
            return len<=11
        }
       
        return true
    }
    
    func checkIsShow() -> Void {
        let checkSting = "no"
        
        if !(self.realNameIsHidden as String == checkSting){
            realNameView.isHidden = true
            nameHeight.constant = 0
            nameTap.constant = 0
        }
        
        if !(self.phoneCheckIsHidden as String == checkSting){
            phoneView.isHidden = true
            phoneVerificationCodeView.isHidden = true

                phoneTap.constant = 0
                phoneHeight.constant = 0
                phoneCodeTap.constant = 0
                phoneCodeHeight.constant = 0

        }
        
        
        if !(self.emailIsHidden as String == checkSting) {
            emailView.isHidden = true
            emailVerificationCodeView.isHidden = true

                    emailTap.constant = 0
                    emailHeight.constant = 0
                    emailCodeHeight.constant = 0
                    codeTap.constant = 0

        }
        
        if !(self.adressIsHidden as String == checkSting) {
            adressView.isHidden = true
            adressHeight.constant = 0
            addressDetailView.isHidden = true
        }
        
    }
    
    
    
    func postCheckEmailCode() -> Void {
        
        RequestHelper.post(atPath: "/clientsAPIs/GetEmailToken", withData: ["email":emailTf.text!], withCompletion: { data in
            let json = JSON(data)
            print(json)
            
            let code = json["success"].boolValue
            if code  {
                DispatchQueue.main.async {
                    UIHelper.alertSimpleMessage(about: "获取邮箱验证码成功", withDescription: "请查看您的邮箱", in: self)
                    
                }
            }else{
                DispatchQueue.main.async {
                    
                    UIHelper.alertSimpleMessage(about: "获取邮箱验证码失败", withDescription: json["msg"].stringValue, in: self)
                    
                }
            }
        },withError: {_ in 
              UIHelper.alertSimpleMessage(about: "服务器异常,获取邮箱验证码失败。\(getErrorString())", withDescription: "", in: self)
        })
    }
    
    
    func postPhoneCode() -> Void {
        RequestHelper.post(atPath: "/clientsAPIs/GetMobileToken", withData: ["mobile":phoneTf.text!], withCompletion: { data in
            let json = JSON(data)
            let code = json["success"].boolValue
            if code  {
                DispatchQueue.main.async {
                    UIHelper.alertSimpleMessage(about: "获取短信验证码成功", withDescription: "请查看您的手机", in: self)
                    
                }
            }else{
                DispatchQueue.main.async {
                    
                    UIHelper.alertSimpleMessage(about: "获取短信验证码失败", withDescription: json["msg"].stringValue, in: self)
                    
                }
            }
        },withError: {_ in
             UIHelper.alertSimpleMessage(about: "服务器异常,获取短信验证码失败。\(getErrorString())", withDescription: "", in: self)
        })
    }
    
    
    func postCheckState() -> Void {
        RequestHelper.post(atPath: "/clientsAPIs/GetVerificationState",
                           withData: ["pagetype":"PROMOTION_PAGE"], withCompletion: { data in
                            let json = JSON(data)
                            let type = json.stringValue
                            let typeAlredyCheck = "SHOW_NEW_FLOW_PAGE"
                            
                            if type == typeAlredyCheck {
                                //进入优惠列表
                                
                                self.navigationController?.popViewController(animated: true)
                                
                            }
                            
        }) {error in
            DispatchQueue.main.async {
                self._loadView?.removeFromSuperview()
                UIHelper.alertSimpleMessage(about: "请求失败", withDescription: "未成功读取状态信息，请稍后重试。\(getErrorString())", in: self)
            }
        }
        
    }
    
    
    
    
    @IBAction func selectAdress(_ sender: Any) {
         addTitleAddressView.addAnimate()
        //跳转地址界面
//        let adressVc = UpdateAddressViewController()
//        adressVc.controllerName = "DiscountsCheckUserInfoVC"
//        
//        ////(六)跳转页面时挂上代理
//        adressVc.delegate_zsj = self
//        self.navigationController?.pushViewController(adressVc, animated: true)
        
        //        adressBtn.setTitle("地址已保存", for:.normal)
        
        
        //                let storyboard = UIStoryboard(name: "Main", bundle: nil)
        //                let threeVC = storyboard.instantiateViewController(withIdentifier: "UpdateAddressViewController") as! UpdateAddressViewController
        //                threeVC.bbchange={
        //                    ( adressAll:String,myColor:UIColor) in
        //                    self.title=adressAll
        //        //            self.view.backgroundColor=myColor
        //
        //                    if (adressAll != nil) {
        //                        self.adressBtn.setTitle(adressAll, for:.normal)
        //                    }
        //
        //                }
        
        
    }
    
    @IBAction func getEmailCode(_ sender: Any) {
        if !checkEmail(email: emailTf.text!) {
            UIHelper.alertSimpleMessage(about: "", withDescription: "邮箱格式错误", in: self)
            return
        }
        
        if emailTf.text != ""{
            startTimer()
            self.postCheckEmailCode()
        }
        
        
    }
    
    @IBAction func getCodeClick(_ sender: Any) {
        
        
        if phoneTf.text!.count == 11{
            startPhoneTimer()
            //获取验证码
            self.postPhoneCode()
        }else{
            UIHelper.alertSimpleMessage(about: "", withDescription: "请输入正确手机号码", in: self)
        }
        
    }
    
    func  startTimer(){
        self.timer.startTimer(second: 120) { (count) in
            if count > 0{
                self.getEmailVerificationBtn.setTitle("\(count)s", for: .normal)
                self.getEmailVerificationBtn.isUserInteractionEnabled = false
            }else{
                self.getEmailVerificationBtn.setTitle("获取验证码", for: .normal)
                self.getEmailVerificationBtn.isUserInteractionEnabled = true
            }
        }
    }
    
    func  startPhoneTimer(){
        self.timer2.startTimer(second: 120) { (count) in
            if count > 0{
                self.getVerificationCode.setTitle("\(count)s", for: .normal)
                self.getVerificationCode.isUserInteractionEnabled = false
            }else{
                self.getVerificationCode.setTitle("获取验证码", for: .normal)
                self.getVerificationCode.isUserInteractionEnabled = true
            }
        }
    }
    
    
    
    @IBAction func checkClick(_ sender: Any) {
        weak var this = self;
        
        var nCode = 1
        var eCode = false
        var pCode = false
        
        
        let address = self.addressDetail.text
         if !self.adressView.isHidden {
            if address?.count == 0 {
            UIHelper.alertSimpleMessage(about: "请输入详细地址", withDescription: "", in: self)
            return
            }
            let arrayID = stringIDs?.components(separatedBy: "=")
            if arrayID == nil {
            UIHelper.alertSimpleMessage(about: "请选择地址", withDescription: "", in: self)
            return
            }else{
                if arrayID!.count == 1{
                UIHelper.alertSimpleMessage(about: "请选择地址", withDescription: "", in: self)
                return
            }
            }
        }
        if self.realNameTf.text!.count == 0 && self.realNameView.isHidden == false {
            UIHelper.alertSimpleMessage(about: "请输入真实姓名", withDescription: "", in: self)
            return
            }
        if  self.phoneTf.text!.count == 0 && self.phoneView.isHidden == false{
            UIHelper.alertSimpleMessage(about: "请输入手机号码", withDescription: "", in: self)
            return
        }
        if self.phoneCodeTf.text!.count == 0 && self.phoneView.isHidden == false{
            UIHelper.alertSimpleMessage(about: "请输入手机验证码", withDescription: "", in: self)
            return
        }
        if  self.emailTf.text!.count == 0 && self.emailView.isHidden == false{
            UIHelper.alertSimpleMessage(about: "请输入邮箱地址", withDescription: "", in: self)
            return
        }
        if  self.emailCodeTf.text!.count == 0 && self.emailView.isHidden == false{
            UIHelper.alertSimpleMessage(about: "请输入邮箱验证码", withDescription: "", in: self)
            return
        }
        
            if !self.self.realNameView.isHidden {
                if self.realNameTf.text?.count ?? 0 > 0 {
                    RequestHelper.post(atPath: "/kz/member/editrealname", withData: ["fullname":(this?.realNameTf.text!)!,"code":(this?.realNameTf.text!)!], withCompletion: { data in
                        let json = JSON(data)
                        nCode = json["c"].intValue
                        if nCode != 0{
                            DispatchQueue.main.async {
                                self._loadView?.removeFromSuperview()
                                UIHelper.alertSimpleMessage(about: "姓名保存失败", withDescription: json["msg"].stringValue, in: self)
                            }
                        }else{
                            DispatchQueue.main.async {
//                                self.realNameView.isHidden = true
                                self.realNameIsHidden = "true"
                                self.checkIsShow()
                                if (self.realNameView.isHidden&&self.emailView.isHidden&&self.phoneView.isHidden&&(self.adressHeight.constant == 0)){
                                    self.typeNeedCheck2()
                                }
                                
                            }
                        }
                    }) { error in
                        DispatchQueue.main.async {
                            self._loadView?.removeFromSuperview()
                            UIHelper.alertSimpleMessage(about: "姓名读取失败", withDescription: "未成功读取活动信息，请稍后重试。\(getErrorString())", in: self)
                        }
                    }
                    
                }else{
                    UIHelper.alertSimpleMessage(about: "请输入真实姓名", withDescription: "", in: self)
                }
            }
            
            
            

            if !self.phoneView.isHidden {
                if self.phoneCodeTf.text?.count ?? 0 > 0 {
                    RequestHelper.post(atPath: "/clientsAPIs/SaveMobile", withData: ["mobile":(this?.phoneTf.text!)!,"code":(this?.phoneCodeTf.text!)!], withCompletion: { data in
                        let json = JSON(data)
                        pCode = json["success"].boolValue
                        if pCode == false{
                            DispatchQueue.main.async {
                                self._loadView?.removeFromSuperview()
                                UIHelper.alertSimpleMessage(about: "手机保存失败", withDescription: json["msg"].stringValue, in: self)
                                
                            }
                        }else{
                            DispatchQueue.main.async {
//                                self.phoneView.isHidden = true
//                                self.phoneVerificationCodeView.isHidden = true
                                self.phoneCheckIsHidden = "true"
                                self.checkIsShow()
                                if (self.realNameView.isHidden&&self.emailView.isHidden&&self.phoneView.isHidden&&(self.adressHeight.constant == 0)){
                                    self.typeNeedCheck2()
                                }
                                
                            }
                        }
                    }) { error in
                        DispatchQueue.main.async {
                            self._loadView?.removeFromSuperview()
                            UIHelper.alertSimpleMessage(about: "手机读取失败", withDescription: "未成功读取活动信息，请稍后重试。\(getErrorString())", in: self)
                        }
                    }
                    
                }else{
                    UIHelper.alertSimpleMessage(about: "请输入手机验证码", withDescription: "", in: self)
                }
            }
            
            
            if !self.emailView.isHidden {
                if this?.emailCodeTf.text?.count ?? 0 > 0{
                    RequestHelper.post(atPath: "/clientsAPIs/SaveEmail", withData: ["email":(this?.emailTf.text!)!,"code":(this?.emailCodeTf.text!)!], withCompletion: { data in
                        
                        let json = JSON(data)
                        eCode = json["success"].boolValue
                        if eCode == false{
                            DispatchQueue.main.async {
                                self._loadView?.removeFromSuperview()
                                UIHelper.alertSimpleMessage(about: "邮箱保存失败", withDescription: json["msg"].stringValue, in: self)
                                
                            }
                        }else{
                            DispatchQueue.main.async {
//                                self.emailView.isHidden = true
//                                self.emailVerificationCodeView.isHidden = true
                                self.emailIsHidden = "true"
                                self.checkIsShow()
                                if (self.realNameView.isHidden&&self.emailView.isHidden&&self.phoneView.isHidden&&(self.adressHeight.constant == 0)){
                                    self.typeNeedCheck2()
                                }
                            }
                        }
                    }) { error in
                        
                        DispatchQueue.main.async {
                            self._loadView?.removeFromSuperview()
                            UIHelper.alertSimpleMessage(about: "邮箱读取失败", withDescription: "未成功读取活动信息，请稍后重试。\(getErrorString())", in: self)
                        }
                    }
                    
                }else{
                    UIHelper.alertSimpleMessage(about: "请输入邮箱验证码", withDescription: "", in: self)
                }
            }
            
        if !self.adressView.isHidden {
            self.addressRequest()
        }
        
     
        //        DispatchQueue.main.async {
        //            self._loadView?.removeFromSuperview()
        //            UIHelper.alertSimpleMessage(about: "提交成功", withDescription: "", in: self)
        //        }
        

        
        
        
    }
    
    
    func addressRequest() {
        
        var provinces_code = ""
        var city_code = ""
        var area_code = ""
        var streets_code = ""
        let address = self.addressDetail.text
        if address?.count == 0 {
            UIHelper.alertSimpleMessage(about: "请输入详细地址", withDescription: "", in: self)
            return
        }
        let arrayID = stringIDs?.components(separatedBy: "=")
        if arrayID == nil {
            UIHelper.alertSimpleMessage(about: "请选择地址", withDescription: "", in: self)
            return
        }else{
            if arrayID!.count == 1{
                UIHelper.alertSimpleMessage(about: "请选择地址", withDescription: "", in: self)
                return
            }
        }
        for index in 0..<arrayID!.count {
            if index == 0 {
                provinces_code = arrayID?[0] ?? ""
            }else if index == 1{
                city_code = arrayID?[1] ?? ""
            }else if index == 2{
                area_code = arrayID?[2] ?? ""
            }else if index == 3{
                streets_code = arrayID?[3] ?? ""
            }
        }
      
        let dic = ["provinces_code":provinces_code,"city_code":city_code,"area_code":area_code,"streets_code":streets_code,"address":address]
        let progress = MBProgressHUD.showMessageNoHiden("", to: self.view)
        RequestHelper.post(atPath: "/clientsAPIs/SaveAddress", withData: dic as! Dictionary<String, String>, withCompletion: { data in
            let json = JSON(data)
            if json["succ"].boolValue{
                DispatchQueue.main.async {
                    progress.removeFromSuperview()
                    self.adressIsHidden = "true"
                    self.checkIsShow()
                    if (self.realNameView.isHidden&&self.emailView.isHidden&&self.phoneView.isHidden&&(self.adressHeight.constant == 0)){
                        self.typeNeedCheck2()
                    }
                }
            }else{
                DispatchQueue.main.async {
                    progress.removeFromSuperview()
                    UIHelper.alertSimpleMessage(about: "更改收货地址失败", withDescription: "", in: self)
                    
                }
            }
        },withError: {_ in
            UIHelper.alertSimpleMessage(about: "服务器异常，更改收货地址失败，\(getErrorString())", withDescription: "", in: self)
        })
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func typeNeedCheck() {
        RequestHelper.post(atPath: "/clientsAPIs/GetVerificationState",
                           withData: ["pagetype":"PROMOTION_PAGE"], withCompletion: { data in
                            let json = JSON(data)
                            let type = json.stringValue
                            let typeNeedCheck = "SHOW_VERIFICATION_PAGE"
                            
                            if type == typeNeedCheck {
                                //需请求验证详情
                                RequestHelper.post(atPath: "/clientsAPIs/GetVerificationAction", withData: ["pagetype":"PROMOTION_PAGE"], withCompletion: {data in
                                    let json = JSON(data)
                                    
                                    DispatchQueue.main.async {
                                        let isEmail = json["has_email"].stringValue
                                        let isMobie = json["has_mobile"].stringValue
                                        let isAdress = json["has_address"].stringValue
                                        let isRealName = json["has_realname"].stringValue
                                        
                                        
                                        
                                        print(isEmail,isMobie,isAdress,isRealName)
                                        let checkUserInfoVC = DiscountsCheckUserInfoVC(nibName:"DiscountsCheckUserInfoVC", bundle:nil)
                                        checkUserInfoVC.realNameIsHidden = isRealName as NSString
                                        checkUserInfoVC.phoneCheckIsHidden = isMobie as NSString
                                        checkUserInfoVC.phoneCodeIsHidden = isMobie as NSString
                                        checkUserInfoVC.emailIsHidden = isEmail as NSString
                                        checkUserInfoVC.emailCodeIsHidden = isEmail as NSString
                                        checkUserInfoVC.adressIsHidden = isAdress as NSString
                                        
                                        self.navigationController?.pushViewController(checkUserInfoVC, animated: true)
                                        
                                    }
                                }, withError: {error in
                                    print(error)
                                    DispatchQueue.main.async {
                                        //                self._loadView?.removeFromSuperview()
                                        UIHelper.alertSimpleMessage(about: "验证失败", withDescription: "验证账户失败，请稍后重试，\(getErrorString())", in: self)
                                    }
                                })
                                
                            }else{
                                
                                //跳转优惠列表
                                DispatchQueue.main.async {
                                    
                                    // UIHelper.alertSimpleMessage(about: "验证成功", withDescription: "", in: self)
                                }
                                
                                RequestHelper.get(atPath: "/clientsAPIs/myactivity", withCompletion: { data in
                                    if let activityInfoArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]]{
                                        DispatchQueue.main.async {
                                            
                                            let vc = PromotionsVC()
                                            vc.dataArray = activityInfoArray
                                            vc.hidesBottomBarWhenPushed=true
                                            self.navigationController?.pushViewController(vc, animated: true)
                                            //  print(Thread.currentThread)
                                        }
                                    }
                                }, withError: { error in
                                    DispatchQueue.main.async {
                                        self._loadView?.removeFromSuperview()
                                        UIHelper.alertSimpleMessage(about: "读取失败", withDescription: "未成功读取活动信息，请稍后重试，\(getErrorString())", in: self)
                                    }
                                })
                                
                            }
                            
        }, withError: { error in
            print(error)
            DispatchQueue.main.async {
                self._loadView?.removeFromSuperview()
             
                UIHelper.alertSimpleMessage(about: "读取失败", withDescription: "未成功读取活动信息，请稍后重试，\(getErrorString())", in: self)
            }
        })
    }
    
    func typeNeedCheck2(){
        if isWithdraw == true{
            if isBindingBank == false{
                //跳转到绑定银行卡
                let vc = UpdateBankViewController()
                vc.isWithdraw = true
                let item = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)
                self.navigationItem.backBarButtonItem = item
                self.navigationController?.pushViewController(vc, animated: true)
            }else{
                //已绑定银行卡 直接跳转
                let vc = WithdrawVC()
                vc.type = 3
                self.navigationController?.pushViewController(vc, animated: true)
            }
          
        }else{
            self.navigationController?.popViewController(animated: true)
        }
        
    }
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */
    
}
